package cn.tedu.v4;

public class Thread_syn {
    public void main(String[] args){
        //创建WC
        WC wc=new WC();
        //创建两个线程
        Thread p1=new Thread(()->{
            wc.go();
        });
        Thread p2=new Thread(()->{
            wc.go();
        });
        p1.start();
        p2.start();
    }


    //创建WC
    class WC{
        public void go(){
            Thread t=Thread.currentThread();
            try {
                System.out.println(t.getName()+"去厕所");
                synchronized (this) {
                    Thread.sleep(5000);
                    System.out.println(t.getName()+"找门进去");
                }
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName()+"走人");
        }
    }
}
